namespace hjc {

	export class PoolManager extends Singleton {

		private $map: Map<string, IPoolable[]> = new Map();
		public claim<T extends IPoolable>(Type: new (...params: any[]) => T, ...params: any[]): T {
			let className = egret.getQualifiedClassName(Type);
			if (!isArray(this.$map.get(className))) this.$map.set(className, []);
			let claimed: any = null;
			if (notEmptyArr(this.$map.get(className))) claimed = this.$map.get(className).shift() as T;
			else claimed = new Type(...params);
			claimed.doFunc(Func.init, ...params);
			return claimed;
		}

		public free(obj: IPoolable): void {
			let className = egret.getQualifiedClassName(obj);
			if (!isArray(this.$map.get(className))) this.$map.set(className, []);
			this.$map.get(className).push(obj);
			if (obj instanceof egret.DisplayObject) ui.remove(obj);
		}

		public clear(Type): void {
			this.$map.delete(egret.getQualifiedClassName(Type));
		}

		public clearAll() {
			this.$map.clear();
		}
	}
}